/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/03/06
* File: RenderSystem.h
**/

#pragma once

#include <render_system/BaseRenderSystem/RenderSystem.h>
#include "OGLVertexBuffer.h"
#include "OGLIndexBuffer.h"

namespace HY
{
class OGLRenderSystem : public RenderSystem
{
public:
	virtual Texture2D* createTexture2D();

	virtual TextureCube* createTextureCube();

	virtual RenderTarget2D* createRenderTarget2D();

	virtual RenderTargetCube* createRenderTargetCube();

	virtual VertexBuffer* createVertexBuffer();

	virtual IndexBuffer* createIndexBuffer();

	virtual VertexShader* createVertexShader();

	virtual PixelShader* createPixelShader();

	virtual Program* createProgram();

	virtual uint32 getRenderState(uint32 state) const;

	virtual bool setRenderState(uint32 state, uint32 value);

	virtual bool setProgram(Program* pro);

	virtual bool beginScene();

	virtual bool endScene();

	virtual const IntRect& getViewport() const;

	virtual bool setViewport(const IntRect& viewport);

	virtual void getColorMask(bool& red, bool& green, bool& blue, bool& alpha) const;

	virtual bool setColorMask(
		bool red = true, 
		bool green = true, 
		bool blue = true, 
		bool alpha = true);

	virtual bool clear(
		uint32 flags = Clear::Color | Clear::ZBuffer, 
		Color clr = Color::BLACK, float z = 1.0f);

	virtual RenderObject* getRenderTarget() const;

	virtual bool setRenderTarget(RenderObject* rtt);

	virtual IndexBuffer* getIndexBuffer();

	virtual bool setIndexBuffer(IndexBuffer* ibuffer);

	virtual VertexBuffer* getVertexBuffer();

	virtual bool setVertexBuffer(VertexBuffer* vbuffer);

	virtual bool drawPrimitives(uint32 type, uint32 start_idx, uint32 num_vertices);

	virtual bool drawIndexedPrimitives(
		uint32 type, uint32 min_idx, uint32 max_idx, 
		uint32 start_idx, uint32 num_vertices);

protected:
	uint32					render_state_[RenderState::Number];
	IntRect					viewport_;
	bool					color_mask_[4];
	RenderObject*			curr_render_target_;
	VertexBuffer*			curr_vb_;
	IndexBuffer*			curr_ib_;
};
}